package com.zixi.ai.rag.controller;

import com.zixi.ai.common.domain.R;
import com.zixi.ai.framework.controller.BaseTemplateController;
import com.zixi.ai.rag.dto.DocumentDto;
import com.zixi.ai.rag.entity.AiKnowledgeEntity;
import com.zixi.ai.rag.service.IAiKnowledgeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.document.Document;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wfg
 */
@RestController
@RequestMapping("/ai/knowledge")
@RequiredArgsConstructor
@Tag(name = "知识库")
public class AiKnowledgeController extends BaseTemplateController<IAiKnowledgeService, AiKnowledgeEntity, Long> {
    @GetMapping("search")
    @Operation(summary = "向量搜索",
            parameters = {
                    @Parameter(name = "id", required = true, description = "ID"),
                    @Parameter(name = "keyword", required = true, description = "关键字搜索"),
            })
    public R<List<Document>> search(@RequestParam("id") Long id, @RequestParam("keyword") String keyword) {
        return service.search(id, keyword);
    }

    @PostMapping(value = "saveText")
    @Operation(summary = "保存文本")
    public R<Boolean> saveText(@RequestParam("knowledgeId") Long knowledgeId, @RequestBody List<DocumentDto> documents)  {
        return R.ok(service.saveText(knowledgeId, documents));
    }
}
